var express = require("express");
var router = express.Router();
const Article = require("../db/models/article");
const User = require("../db/models/user");
const { getPageParams } = require("../core/page");
const {getArticlesByPage}  = require('../core/article')
/* GET users listing. */
// 获取站长的文章
router.get("/", getArticlesByPage)

module.exports = router;

// 分页获取文章
// router.get("/master", async function (req, res, next) {
//   console.log("req.query.pageSize:", req.query.pageSize);

//   const uid = 16;
//   //   传过来的是字符串,需要自己处理成数字类型的,比如limit 之类的
//   const { pageSize, pageIndex } = req.query;

//   const pageParams = getPageParams({ pageSize, pageIndex });
//   let ret = await Promise.all([
//     Article.findAll({
//       ...pageParams,
//       where: {
//         uid,
//       },
//     }),
//     User.findOne({ where: { id: uid } }),
//     Article.count({
//       where: {
//         uid,
//       },
//     }),
//   ]);
//   delete ret[1].dataValues.id;
//   delete ret[1].dataValues.pwd;
//   const list =
//     ret[0]?.map((article) => ({
//       ...article.dataValues,
//       ...ret[1].dataValues,
//     })) || [];
//   res.send({
//     code: 200,
//     data: {
//       list,
//       total: ret[2],
//       current: +pageIndex,
//       size: +pageSize,
//     },
//   });
//   // next()
// });



module.exports = router;
